import java.lang.reflect.Field;
import java.util.HashMap;

/**
 * @Author wonghiu
 * @Date 2021/6/17 8:16
 * @Version 1.0.1
 */
public class HashMapCheck {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
//        HashMap<String,String> stringStringHashMap2 = new HashMap<>();
//        MyHashMap<String,String> stringStringHashMap = new MyHashMap<>();
//        stringStringHashMap.put("111","222");
//        System.out.println(stringStringHashMap.size());
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>(13);
        objectObjectHashMap.put("11","11");
        System.out.println("Thr: "+checkMapThr(objectObjectHashMap));
        System.out.println("Cap: "+checkMapCap(objectObjectHashMap));


    }
    public static int checkMapThr(HashMap<Object, Object> map) throws NoSuchFieldException, IllegalAccessException {
        Class clazz = map.getClass();
        Field threshold = clazz.getDeclaredField("threshold");
        threshold.setAccessible(true);
        return (int) threshold.get(map);
    }
    public static int checkMapCap(HashMap<Object, Object> map) throws NoSuchFieldException, IllegalAccessException {
        Class clazz = map.getClass();
        Field table = clazz.getDeclaredField("table");
        table.setAccessible(true);
        Object[] o = (Object[]) table.get(map);
        return o.length;
    }
}
class MyHashMap<K,V> extends HashMap{

    @Override
    public Object put(Object key, Object value) {

        return super.put(key, value);
    }
}
